<template>
  <div class="logout">
    正在退出，{{ second }}秒后跳转。。。
  </div>
</template>

<script>
export default { name: 'login' }
</script>
<script setup>
import { ref, reactive, onMounted, watch } from 'vue';
import { http } from '@/utils/http/index';
import { useAuthStore } from '@/stores/modules/auth.js'
import { useRouter } from 'vue-router'

/* 路由 */
const router = useRouter()

const authStore = useAuthStore()

const second = ref(3)

/* 退出 */
const logoutDo = () => {
  http.$GET("/Home/LoginOutDo").then(res => {
    if(res.isError) return ElMessage.warning(res.message)
    const timer = setInterval(() => {
      second.value = second.value - 1

      if(second.value === 0) {
        clearInterval(timer)
        /**清除之前的记录 */
        authStore.cleanAuthInfo()
        if (router.currentRoute.value.query.returnUrl) {
          window.open(router.currentRoute.value.query.returnUrl, "_self")
        } else {
          router.push({
            path: '/Home/Login',
            query: router.currentRoute.value.query ? router.currentRoute.value.query : {}
          })
        }
      }
    }, 1000)
    
  })
}

logoutDo()
</script>

<style lang="scss" scoped>
.logout{
  padding: 10px;
  color: blue;
  text-decoration: underline;
}
</style>